﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TemplateWizard;
using EnvDTE;
using EnvDTE80;
using VsWebSite;

namespace CompositeMvcWizard
{
    public class Wizard : IWizard
    {
        public void BeforeOpeningFile(EnvDTE.ProjectItem projectItem)
        {
        }

        public void ProjectFinishedGenerating(EnvDTE.Project project)
        {
        }

        public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem)
        {
        }

        public void RunFinished()
        {
            //TODO: Adding dynamically project references doesn't work! For now we will add manually,it is not the end of the world!
            //EnvDTE._DTE dte = (EnvDTE._DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");
            //var solution = dte.Solution;

            //Project projDomain = solution.Projects.Item(3);
            //VSWebSite projWeb = (VSWebSite)solution.Projects.Item(1).Object;
            //VSLangProj.VSProject projTest = (VSLangProj.VSProject)solution.Projects.Item(2).Object;

            //projWeb.References.AddFromProject(projDomain);
            //projTest.References.AddProject(projDomain);

        }

        public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            if (replacementsDictionary.ContainsKey("$safeprojectname$"))
            {
                if (!replacementsDictionary.ContainsKey("$myprojectname$") || string.IsNullOrEmpty(replacementsDictionary["$myprojectname$"]))
                {
                    string prefix = replacementsDictionary["$safeprojectname$"].Split('.')[0];
                    replacementsDictionary.Add("$myprojectname$", prefix);
                }
            }
        }

        public bool ShouldAddProjectItem(string filePath)
        {
            return true;
        }
    }
}
